﻿Imports System.IO
Imports System.Data

Partial Class WebUserControls_ElencoGallery
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        CaricaRepeaterInEvidenza("")
    End Sub

    Public Sub CaricaRepeaterInEvidenza(ByVal inizialeLocale As String)
        Try


            Dim di As DirectoryInfo = New DirectoryInfo(Server.MapPath("/"))
            Dim dirPath As String = di.FullName & "localimages"

            Dim LocaliDirs() As String = System.IO.Directory.GetDirectories(Path.Combine(dirPath), inizialeLocale & "*") 'Ottengo il path fino all'Elenco dei locali

            Dim dt As New DataTable
            dt.Columns.Add("Locale")
            dt.Columns.Add("ImgAddress")
            dt.Columns.Add("AlbumTitle")
            Dim li As String = ""
            For Each Loc As String In LocaliDirs
                '  Throw New Exception(Loc)
                Dim localeStr As String = Loc.Split("\")(Loc.Split("\").Length - 1).Replace("_", " ")
                '   Throw New Exception(localeStr)
                Dim AlbumDirs() As String = System.IO.Directory.GetDirectories(Path.Combine(Loc)) 'Per ogni locale estraggo tutti gli album che contengono il testo "_TOP_"

                For Each str As String In AlbumDirs 'str contiene nel nome _TOP_
                    If System.IO.Directory.GetFiles(str).Length > 0 Then
                        Dim strFirsFile = System.IO.Directory.GetFiles(str)(0)
                        strFirsFile = strFirsFile.Replace(di.FullName, "../").Replace("\", "/")
                        dt.Rows.Add(localeStr, strFirsFile, str.Split("\")(str.Split("\").Length - 1).Replace("_", " "))
                    End If

                    'li =
                    'aList.Add(li)
                Next
            Next


            RptAlbum.DataSource = dt
            RptAlbum.DataBind()
            LblGallery.Text = ""
        Catch ex As Exception
            LblGallery.Text = ex.Message
        End Try
    End Sub

    Protected Sub LinkButton_Click(sender As Object, e As System.EventArgs) Handles LinkButton_A.Click, LinkButton_B.Click, LinkButton_C.Click, LinkButton_D.Click, LinkButton_E.Click, LinkButton_F.Click, LinkButton_G.Click, _
    LinkButton_H.Click, LinkButton_I.Click, LinkButton_J.Click, LinkButton_K.Click, LinkButton_L.Click, LinkButton_M.Click, LinkButton_N.Click, LinkButton_O.Click, _
    LinkButton_P.Click, LinkButton_Q.Click, LinkButton_R.Click, LinkButton_S.Click, LinkButton_T.Click, LinkButton_U.Click, LinkButton_V.Click, LinkButton_X.Click, _
    LinkButton_W.Click, LinkButton_Z.Click, LinkButton_All.Click

        Dim filtro As String = sender.id.ToString.Split("_")(1).ToUpper
        If filtro = "ALL" Then
            CaricaRepeaterInEvidenza("")
        Else
            CaricaRepeaterInEvidenza(filtro)

        End If
    End Sub
End Class
